#include "bsp_delay.h"
#include "app.h"


//有一种dwt计时器的方式
//过几天不忙了再更新

void Delay_us(uint32_t udelay)    //定义hal库us级延迟
{
    uint32_t startval, tickn, delays, wait;

    startval = SysTick->VAL;
    tickn = HAL_GetTick();
    delays = udelay * 169;
    if (delays > startval)
    {
        while (HAL_GetTick() == tickn)
        {
        }
        wait = 1690000 + startval - delays;
        while (wait < SysTick->VAL)
        {
        }
    }
    else
    {
        wait = startval - delays;
        while (wait < SysTick->VAL && HAL_GetTick() == tickn)
        {
        }
    }
}
